﻿<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>


					<article>
						<h2>Paieska pagal bury</h2>
						<p>Pildyk forma</p>
						
					  <form autocomplete="off" action="burys.php" method="post" name="search">
					    <p>
					    </p>
					    <table  border="0">
					      <tr>
					        <td width="40"align="right">Burys</td>
					        <td><input name="burys" type="text" size="3" autofocus/></td>
					        <td width="50"align="right">Brigada</td>
					        <td><input name="brigada" type="text" size="3"/></td>
					        <td width="40"align="right">Lova</td>
					        <td><input name="lova" type="text" size="3"/></td>
				          </tr>
				        </table>
					    
					    <p>
					      <input name="Submit" type="submit" value="Paieška" />
					    </p>
					  </form>
    
<?php  

if (isset($_POST['Submit'])){
	if (isset($_POST['burys']) && !empty($_POST['burys'])){
		echo "Burys: " . $_POST['burys']. "</br>";
		$burys = $_POST['burys'];
	};	
	if (isset($_POST['brigada']) && !empty($_POST['brigada'])){
		echo "Brigada: " . $_POST['brigada']. "</br>";
		$brigada = $_POST['brigada'];
	};
	if (isset($_POST['lova']) && !empty($_POST['lova'])){
		//echo "Lovos Nr: " . $_POST['lova']. "</br>";
		$lova = $_POST['lova'];
	};	
	

	// Normalus query:

	$sql = "SELECT * ";
	$sql .= "FROM `user`, lovos ";
	$sql .= "WHERE `user`.lovosid = lovos.lovosid ";
	//$sql .= 
	if (isset($_POST['burys']) && !empty($_POST['burys'])){
			//echo "Bylos Nr: " . $_POST['bylosnr']. "</br>";
			$sql .= " AND `lovos`.burys = '" . $_POST['burys'] . "'";
		};	
	//Tikrinam ar yra yrashytas vardas
	if (isset($_POST['brigada']) && ($_POST['brigada']) != null ){
		//echo "</br> YRA VARDAS </br>";
		$sql .= " AND `lovos`.brigada =";
		$sql .= "'".$_POST['brigada']."'";
	} else { 
		//echo "</br> NERA VARDO </br>";
	};
	//Tikrinam ar yra yrasyta pavarde
	if (isset($_POST['lova']) && ($_POST['lova']) != null ){
		//echo "</br> YRA pavarde </br>";
		$sql .= " AND `lovos`.lova =";
		$sql .= "'".$_POST['lova']."'";
	} else { 
		//echo "</br> NERA Pavardes </br>";
	};
	$sql .= " ORDER BY `user`.`lovosid` ASC";
	
//echo "SQL query: ".$sql . "</br>";
	//Bandom procesinti query
	$result = mysql_query($sql, $connection);
	if ($result) {
		// Success!
		//echo "Successs!! </br>";
	} else {
		// Display error message.
		echo "<p>Subject creation failed.</p>";
		echo "<p>" . mysql_error() . "</p>";
	};
	//xz kas bus
	//$subject = mysql_fetch_array($result);
	//print_r ($subject) ;

				// kazkaip formuotas table'as
			$out = "<table border=\"1\">";
			$out .= "<tr>";
			$out .= "<th>Name</th>";
			$out .= "<th>Surname</th>";
			$out .= "<th>Bylos Nr.</th>";
			$out .= "<th>Brigada</th>";	
			$out .= "<th>Burys</th>";	
			$out .= "<th>Lova</th>";			
			$out .= "</tr>";
					  
		do { 
			$out .= "<tr";
			if (($row_result['etapas']) == 0) {
				$out .=" bgcolor=\"#DDFFCC\"";
			} elseif (($row_result['etapas']) == 1) {
				$out .=" bgcolor=\"#FFFBC1\"";
			};
			$out .= ">";
			$out .= "<td>";
			$out .= "<a href=\"summary.php?userid=";
			$out .= $row_result['userid'];
			$out .= "\">";
			$out .= $row_result['vardas'];
			$out .= "</a>";
			$out .= "</td>";
			$out .= "<td>";
			$out .= "<a href=\"summary.php?userid=";
			$out .= $row_result['userid'];
			$out .= "\">";
			$out .= $row_result['pavarde'];
			$out .= "</a>";
			$out .= "</td>";
			$out .= "<td";
			if (($row_result['etapas']) == 0) {
				$out .=" bgcolor=\"#DDFFCC\"";
			} elseif (($row_result['etapas']) == 1) {
				$out .=" bgcolor=\"#FFFBC1\"";
			};
			$out .= ">";
			$out .= $row_result['bylosnr'];
			$out .= "</td>";
			$out .= "<td";
			if (($row_result['etapas']) == 0) {
				$out .=" bgcolor=\"#DDFFCC\"";
			} elseif (($row_result['etapas']) == 1) {
				$out .=" bgcolor=\"#FFFBC1\"";
			};
			$out .= ">";
			$out .= $row_result['burys'];
			$out .= "</td>";
			$out .= "<td";
			if (($row_result['etapas']) == 0) {
				$out .=" bgcolor=\"#DDFFCC\"";
			} elseif (($row_result['etapas']) == 1) {
				$out .=" bgcolor=\"#FFFBC1\"";
			};
			$out .= ">";
			$out .= $row_result['brigada'];
			$out .= "</td>";
			$out .= "<td";
			if (($row_result['etapas']) == 0) {
				$out .=" bgcolor=\"#DDFFCC\"";
			} elseif (($row_result['etapas']) == 1) {
				$out .=" bgcolor=\"#FFFBC1\"";
			};
			$out .= ">";
			$out .= $row_result['lova'];
			$out .= "</td>";
			
			$out .= "</tr>";

		 } while ($row_result = mysql_fetch_assoc($result)); 
			$out .= "</table><br>";
				echo $out;
	
	
};

			
?>

					</article>
		
            
<?php require("includes/footer.php"); ?>